<template>
	<view>
		<view class="uni-list">
			<view class="uni-list-cell uni-list-cell-pd able">
				<view class="uni-list-cell-db able" @click="handlerItemClick('edit')">编辑资料</view>
				<text class="uni-navigate-icon uni-icon">&#xe470;</text>
			</view>
			<view class="uni-list-cell uni-list-cell-pd">
				<view class="uni-list-cell-db">消息推送</view>
				<switch :checked="xxts" color="#000" class="miniswitch" />
			</view>
			<view class="uni-list-cell uni-list-cell-pd able" @click="handlerItemClick('about')">
				<view class="uni-list-cell-db">关于我们</view>
				<text class="uni-navigate-icon uni-icon">&#xe470;</text>
			</view>
			<view class="uni-list-cell uni-list-cell-pd able" v-if="$global.platform != 'H5'"
				@click="handlerItemClick('clear')">
				<view class="uni-list-cell-db">清理缓存</view>
				<view class="solttext">{{cachesize}}</view>
			</view>
		</view>
		<button type="default" class="logout" @click="logout">退出登录</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				xxts: true,
				cachesize: 0
			}
		},
		methods: {
			handlerItemClick: function (name) {
				var vm = this;
				if (name == 'about') {
					uni.navigateTo({
						url: '/pages/about/about'
					});
				}
				if (name == 'edit') {
					uni.navigateTo({
						url: '/pages/mine/edit'
					});
				}
				if (name == 'clear') {
					//可以询问用户是否删除
					uni.showModal({
						title: '提示',
						content: '确定清除缓存吗?',
						success(res) {
							if (res.confirm) {
								plus.cache.clear(function () {
									uni.showToast({
										title: '清除成功',
										icon: 'none',
										success() {
											vm.getCacheSize();
										}
									})
								});
							}
						}
					})
				}
			},
			logout: function () {
				this.$store.commit("userStatus", '');
				uni.setStorageSync('userStatus', '');
				uni.reLaunch({
					url: '/pages/index/index?onload=true'
				});
			},
			getCacheSize: function () {
				var vm = this;
				if (vm.$global.platform == 'APP') {
					plus.cache.calculate(function (size) {
						if (size < 1024) {
							vm.cachesize = size + 'B';
						} else if (size / 1024 >= 1 && size / 1024 / 1024 < 1) {
							vm.cachesize = Math.floor(size / 1024 * 100) / 100 + 'KB';
						} else if (size / 1024 / 1024 >= 1) {
							vm.cachesize = Math.floor(size / 1024 / 1024 * 100) / 100 + 'M';
						}
					});
				}
			}
		},
		onLoad() {
			this.getCacheSize();
		}
	}
</script>

<style lang="scss" scoped>
	.uni-list-cell::after {
		background: none;
	}

	.uni-list:after {
		background: none;
	}

	.logout {
		margin: 50pt auto;
		display: block;
		width: 90px;
		font-size: 13px;
		padding: 0 1.34em;
		color: #fff;
		background-color: #000000;

		&.button-hover {
			background-color: #303030;
			color: hsla(0, 0%, 100%, .6)
		}
	}
</style>